{% extends "common/layout_main.html" %}
{% block content %}
<div class="row  border-bottom">
    <div class="col-lg-12">
        <div class="tab_title">
            <ul class="nav nav-pills">
                <li>
                    <a href="{{ url_for('food_page.index') }}">美食列表</a>
                </li>
                <li class="current">
                    <a href="{{ url_for('food_page.category') }}">分类列表</a>
                </li>
            </ul>
        </div>
    </div>
</div>
<div class="row m-t  wrap_category_insert">
	<div class="col-lg-12">
		<h2 class="text-center">分类设置</h2>
		<div class="form-horizontal m-t m-b">
			<div class="form-group">
				<label class="col-lg-2 control-label">分类名称:</label>
				<div class="col-lg-10">
					<input type="text" name="cate_name" class="form-control" placeholder="请输入分类名称~~" value="">
				</div>
			</div>
			<div class="hr-line-dashed"></div>
			<div class="form-group">
				<label class="col-lg-2 control-label">权重:</label>
				<div class="col-lg-10">
					<input type="text" name="cate_weight" class="form-control" placeholder="请输入分类权重~~" value="">
				</div>
			</div>
			<div class="hr-line-dashed"></div>
			<div class="form-group">
				<div class="col-lg-4 col-lg-offset-2">
					<button class="btn btn-w-m btn-outline btn-primary save">保存</button>
				</div>
			</div>
		</div>
	</div>
</div>
{% endblock %}
{% block js %}
<script>
	var category_insert = {
		init:function(){
			this.eventBind()
		},
		eventBind:function(){
            $(".wrap_category_insert .save").click(function(){
                var name_target = $(".wrap_category_insert input[name=cate_name]");
                var weight_target = $(".wrap_category_insert input[name=cate_weight]");
                var name = name_target.val();
                var weight = weight_target.val();

                if (name == "" || name.length < 1){
                    common_ops.tip("请输入正确的名称！",name_target)
                    return ;
                }
                if (weight == ""){
                    common_ops.tip("请输入权重！",weight_target)
                    return ;
                }

                $.ajax({
                    url:"/food/category-insert",
                    type:"POST",
                    data:{"name":name,"weight":weight},
                    dataType:"json",
                    success:function(res){
                        var callback = null
                        if(res.code == 200){
                            callback = function(){
                                window.location.href = "/food/category"
                            }
                            common_ops.alert(res.msg,callback)
                        }
                        if(res.code == -1){
                            common_ops.alert(res.msg)
                        }
                    }
                })

            });
		}
	}
    $(document).ready(function(){
        category_insert.init();
    })

</script>
{% endblock %}
